
var audioElement = null;

var vue = new Vue({
  el: "#app",
  data() {
    return {
      checked: false,
      videoList: [],
      tempVideoList: [],
      audioList: [],
      mobile: "",

      apiBaseUrl: "https://ylhdwh.com/services",

      // 咪咕音乐SDK相关
      miguSDKInitialized: false,
      channelCode: "002123U", // 渠道号，需要使用咪咕音乐开放平台分配的正确渠道号 002123U
      cpid: "test", // cpid，需要使用咪咕音乐开放平台分配的正确cpid

      // 咪咕登录接口相关

      serviceId: "698039020050006035", // 服务ID，需要与咪咕平台线下约定
      callerId: "600923018000000007", // 主叫视频彩铃功能Id

      bizInfoMon: {
        bizCode: "",
        count: 0,
        originalPrice: 0,
        salePrice: 0,
        offReason: "",
        desc: "",
        Hold1: "",
        hold2: "",
        cpId: "",
        cpparam: "",
      },

      // Toast消息相关
      showToast: false,
      toastMessage: "",
      toastType: "info",

      // 购买成功状态
      buySuccess: false,

      token: "",

      isVip: false,

      // 视频弹窗相关
      showVideoModal: false,
      currentVideo: {
        filePath: "",
        fileImage: "",
      },
      currentAudioIndex: -1,

      // 登录弹窗相关
      isReturning: false,
      showLoginModal: false,
      loginForm: {
        phone: "",
        code: "",
      },
      agreeTerms: false,

      // 验证码倒计时
      codeCountdown: 0,
      codeTimer: null,

      // 确认弹窗相关
      showConfirmModal: false,

    };
  },
  mounted() {
    window.initCallBack = this.initCallBack;
    window.queryStrategyBYBCallback = this.queryStrategyBYBCallback;
    window.miguBJYHOrderCallback = this.miguBJYHOrderCallback;
    window.openAndMonthGWCCallback = this.openAndMonthGWCCallback;
    window.commonCancelCallback = this.commonCancelCallback;
    this.initMiguSDK();
    this.loadMusicList();
    this.loadVideoList();
  },
  methods: {
    // 初始化咪咕音乐SDK
    initMiguSDK() {
      try {
        console.log("开始初始化咪咕音乐SDK");
        // 检查SDK是否已加载
        if (typeof openMiGuInit === "undefined") {
          console.error("咪咕音乐SDK未加载");
          this.showToastMessage("咪咕音乐SDK加载失败", "error");
          return;
        }

        // 调用初始化方法 - mconf版本
        // openMiGuInit(渠道号, '回调方法名','mconf','','','d_ff5075')
        openMiGuInit(
          this.channelCode,
          "initCallBack",
          "mconf",
          "",
          "",
          "d_ff5075"
        );
        console.log(
          "咪咕音乐SDK初始化调用完成 - mconf版本, 渠道号:",
          this.channelCode
        );
      } catch (error) {
        console.error("咪咕音乐SDK初始化失败:", error);
        this.showToastMessage("咪咕音乐SDK初始化失败", "error");
      }
    },

    initCallBack(result) {
      console.log("处理咪咕SDK初始化结果:", result);
      try {
        if (result && result.resultCode === "0000") {
          this.miguSDKInitialized = true;
          this.token = result.token || null;
          //this.showToastMessage("咪咕音乐SDK初始化成功", "success");
          console.log("咪咕音乐SDK初始化成功，Token:", this.token);
        } else {
          this.showToastMessage(
            "咪咕音乐SDK初始化失败: " + (result.message || "未知错误"),
            "error"
          );
          console.error("咪咕音乐SDK初始化失败:", result);
        }
      } catch (error) {
        console.error("处理咪咕SDK初始化结果时出错:", error);
        this.showToastMessage("处理SDK初始化结果失败", "error");
      }
    },

    // 加载音频列表
    async loadMusicList() {
      this.musicLoading = true;
      try {
        // 构建请求参数
        const params = {
          musicName: "",
          musicSinger: "",
          contentId: "",
        };

        // 构建查询字符串
        const queryString = new URLSearchParams(params).toString();
        const apiUrl = `${this.apiBaseUrl}/getMusicList?${queryString}`;

        console.log("加载音频列表 - API URL:", apiUrl);

        const response = await fetch(apiUrl, {
          method: "GET",
          headers: {
            "Content-Type": "application/json",
          },
        });

        if (response.ok) {
          const data = await response.json();
          console.log("音频列表API响应:", data);
          const fullList = data.data || data || [];
          this.audioList = fullList.slice(0, 10);
          //   this.showToastMessage("音频列表加载成功", "success");
        }
      } catch (error) {
        console.error("加载音频列表失败:", error);
      } finally {
        this.musicLoading = false;
      }
    },

    // 加载视频列表
    async loadVideoList() {
      this.videoLoading = true;
      try {
        // 构建请求参数，添加mobile和channelCode
        // 如果参数为空，使用默认值或跳过API调用直接使用模拟数据

        const params = {
          mobile: this.mobile,
          channelCode: this.channelCode,
        };

        // 构建查询字符串
        const queryString = new URLSearchParams(params).toString();
        const apiUrl = `${this.apiBaseUrl}/getVideoList?${queryString}`;

        console.log("加载视频列表 - API URL:", apiUrl);
        console.log("请求参数:", params);

        const response = await fetch(apiUrl, {
          method: "GET",
          headers: {
            "Content-Type": "application/json",
          },
        });

        if (response.ok) {
          const data = await response.json();
          console.log("视频列表API响应:", data);
          const fullList = data.data || data || [];
          // 只保留前4条记录
          this.videoList = fullList.slice(0, 4);
          //   this.showToastMessage("视频列表加载成功", "success");
        } else {
          console.warn("视频列表API不可用，使用模拟数据");
          // 如果API不可用，使用模拟数据
        }
      } catch (error) {
        console.error("加载视频列表失败:", error);
        // 使用模拟数据
      } finally {
        this.videoLoading = false;
      }
    },

    // 开始走提交流程，
    submit() {
      // 校验数据完整性，是否checked，是否有mobile，mobile格式是否正确

      if (!this.mobile) {
        this.showToastMessage("请输入手机号", "warning");
        return;
      }

      if (!this.checked) {
        this.showConfirmModal = true;
        return;
      }

      // 校验手机号格式
      if (!/^1[3456789]\d{9}$/.test(this.mobile)) {
        this.showToastMessage("手机号格式错误", "warning");
        return;
      }

      const params = {
        mobile: this.mobile,
        channelCode: this.channelCode,
        cpid: this.cpid,
      };

      const loginUrl = `${this.apiBaseUrl}/login?${new URLSearchParams(
        params
      ).toString()}`;

      console.log("loginUrl", loginUrl);
      fetch(loginUrl, {
        method: "GET",
        headers: {
          "Content-Type": "application/json",
        },
      })
        .then((response) => response.json())
        .then((data) => {
          console.log("登录API响应:", data);
          if (data.state === "success") {
            this.token = data.token || data.data?.token;

            if (this.token) {
              sessionStorage.setItem("migu_token", this.token);
              sessionStorage.setItem("migu_user_phone", this.mobile);
              sessionStorage.setItem("isLoggedIn", true);
            }
            // 判断是否已订购包月,P2310
            this.checkMonthlySubscription();

            this.showToastMessage("登录成功", "success");
            // 登录成功后的处理逻辑
            this.showLoginModal = false;
          } else {
            this.showToastMessage(
              "登录失败: " + (data.message || "未知错误"),
              "error"
            );
          }
        })
        .catch((error) => {
          console.error("登录请求失败:", error);
          this.showToastMessage("登录请求失败", "error");
        });
    },

    // 检查是否已订购包月
    checkMonthlySubscription() {
      try {
        const params = {
          channelCode: this.channelCode,
          token: this.token,
          serviceId: this.serviceId,
          mobile: this.mobile,
        };

        const url = `${this.apiBaseUrl}/bjhyQuery?${new URLSearchParams(
          params
        ).toString()}`;

        fetch(url, {
          method: "GET",
          headers: {
            "Content-Type": "application/json",
          },
        })
          .then((response) => response.json())
          .then((res) => {
            console.log("检查是否已订购包月API响应:", res);
            if (res.state === "success") {
              if (res.data?.resCode === "000000") {

                if (res.data?.status === "0") {
                  this.isVip = true;
                  sessionStorage.setItem("isVip", true);
                  this.showToastMessage("您已订购包月", "success");
                } else {
                  // 判断主叫  P23A5
                  this.checkCallerRingtoneFunction();
                  // this.showToastMessage("未订购包月", "info");
                }
              } else {
                this.showToastMessage(res.data?.resMsg, "info");
              }
            }
          })
          .catch((error) => {
            console.error("检查是否已订购包月失败:", error);
          });
      } catch (error) {
        console.error("检查是否已订购包月失败:", error);
      }
    },

    checkCallerRingtoneFunction() {
      try {
        const params = {
          channelCode: this.channelCode,
          token: this.token,
          mobile: this.mobile,
        };

        const url = `${this.apiBaseUrl}/queryVrbtStatus?${new URLSearchParams(
          params
        ).toString()}`;

        fetch(url, {
          method: "GET",
          headers: {
            "Content-Type": "application/json",
          },
        })
          .then((response) => response.json())
          .then((data) => {
            console.log("检查主叫彩铃功能API响应:", data);
            if (data.state === "success") {
              const { status } = data.data;

              switch (status) {

                case "3":
                  console.log("有主叫功能 - 策略环节（包月包集或者单次P2407）");
                  this.handleStrategySelection();
                  break;
                default:
                  console.log("无主叫功能 - 订购包月彩铃主叫（包月包集P2348）");
                  this.subscribeMonthlyCallerRingtone();
                  break;
              }
            }
          })
          .catch((error) => {
            console.error("检查主叫彩铃功能失败:", error);
          });
      } catch (error) {
        console.error("检查主叫彩铃功能失败:", error);
      }
    },

    // 策略环节（包月包集或者单次P2407）
    handleStrategySelection() {
      // 调用P2407包月包策略查询接口
      try {
        console.log("策略环节（包月包集或者单次P2407）");
        const strategyData = {
          channelCode: this.channelCode,
          token: this.token,
          serviceId: this.serviceId, // 可选参数，根据业务需要填写
          count: "1", // 查询1个月的策略  //todo 需要确定多少个月、
          type: "14", // 固定值
          youCallbackName: "miguQueryStrategyBYBCallback",
        };
        console.log("调用P2407包月包策略查询接口");
        queryStrategyBYB(strategyData);
      } catch (error) {
        console.error("查询策略失败:", error);
      }
    },

    queryStrategyBYBCallback(data) {
      console.log("P2407包月包策略查询结果:", result);
      if (result.resCode === "000000") {
        this.showToastMessage("包月包策略查询成功！", "success");

        // 处理策略信息
        if (result.bizInfoMon) {
          console.log("bizInfoMon:", result.bizInfoMon);
          this.bizInfoMon = result.bizInfoMon;
          this.subscribeMonthlyPackage();
        }
      } else {
        const errorMsg = result.resMsg || "包月包策略查询失败";
        this.showToastMessage(errorMsg, "error");
        console.error("P2407接口错误:", result);
      }
    },

    // 开通包月（订购P2265）
    async subscribeMonthlyPackage() {
      try {
        console.log("调用接口P2265 - 开通包月");
        this.showToastMessage("正在开通包月服务...", "info");

        // 调用P2265白金会员话费订购接口
        const orderData = {
          youCallbackName: "miguBJYHOrderCallback",
          channelCode: this.channelCode,
          token: this.userInfo.token,
          serviceId: this.serviceId,
          cpId: this.bizInfoMon.cpId,
          bizCode: this.bizInfoMon.bizCode,
          cpparam: this.bizInfoMon.cpparam,
          salePrice: this.bizInfoMon.salePrice,
          name: "miguBJYHOrder",
          excode: "0001", // todo 4位渠道自编码
          defSeq: this.generateTimestamp().toString(),
        };

        miguBJYHOrder(orderData);
      } catch (error) {
        console.error("开通包月失败:", error);
        this.showToastMessage("开通包月失败", "error");
      }
    },

    miguBJYHOrderCallback(data) {
      if (result.resCode === "000000") {
        // this.showToastMessage("包月服务开通成功！", "success");
        // 订购成功去执行P23A6
        // todo 弹出订购成功弹窗
        this.buySuccess = true;
        this.isVip = true;
        sessionStorage.setItem("isVip", true);
      } else {
        const errorMsg = result.resMsg || "包月服务开通失败";
        this.showToastMessage(errorMsg, "error");
      }
    },

    // 订购包月彩铃主叫（接口P2348）
    async subscribeMonthlyCallerRingtone() {
      try {
        console.log("调用接口P2348 - 打包订购包月+主叫");
        const data = {
          youCallbackName: "openAndMonthGWCCallback",
          channelCode: this.channelCode,
          token: this.token,
          serviceId: this.serviceId + "," + this.callerId,
        };
        console.log("调用接口P2348 - data:" + JSON.stringify(data, null, 2));
        openAndMonthGWC(data);
      } catch (error) {
        console.error("订购包月彩铃主叫失败:", error);
        this.showToastMessage("订购包月彩铃主叫失败", "error");
      }
    },

    openAndMonthGWCCallback(result) {
      console.log("P2348订购包月彩铃主叫回调:", result);
      if (result.resCode === "000000") {
        // 订购成功处理
        this.buySuccess = true;
        this.isVip = true;
        sessionStorage.setItem("isVip", true);
        this.showToastMessage("订购包月彩铃主叫成功！", "success");

        // 不再自动隐藏弹窗，让用户选择操作
        // 用户可以通过弹窗按钮选择跳转或关闭
      } else {
        const errorMsg = result.resMsg || "订购包月彩铃主叫失败";
        this.showToastMessage(errorMsg, "error");
      }
    },



    cancelSubscription() {
      try {
        console.log("调用接口P2387 - 取消订购");
        const data = {
          youCallbackName: "commonCancelCallback",
          channelCode: this.channelCode,
          token: this.token,
          serviceId: this.serviceId,
          cancelType: "0",
        };
        commonCancel(data);
      } catch (error) {
        console.error("取消订购失败:", error);
        this.showToastMessage("取消订购失败", "error");
      }
    },

    commonCancelCallback(result) {
      console.log("P2387取消订购回调:", result);
      if (result.resCode === "000000") {
        // 订购成功处理
        this.isVip = false;
        sessionStorage.setItem("isVip", false);
        this.showToastMessage("取消订购成功！", "success");
      } else {
        const errorMsg = result.resMsg || "取消订购失败";
        this.showToastMessage(errorMsg, "error");
      }
    },


    sendCode() {
      // sendSms  mobile cpid

      if (!this.loginForm.phone) {
        this.showToastMessage("请输入手机号码", "error");
        return;
      }

      if (!/^1[3-9]\d{9}$/.test(this.loginForm.phone)) {
        this.showToastMessage("请输入正确的手机号码", "error");
        return;
      }

      // 检查协议同意状态
      // if (!this.agreeTerms) {
      //   this.showToastMessage("请先同意用户协议和隐私政策", "error");
      //   return;
      // }

      if (this.codeCountdown > 0) {
        this.showToastMessage("请稍后再发送", "info");
        return;
      }

      const params = {
        mobile: this.loginForm.phone,
        cpid: this.channelCode,
      };
      const queryString = new URLSearchParams(params).toString();
      const url = `${this.apiBaseUrl}/sendSms?${queryString}`;
      fetch(url, {
        method: "GET",
        headers: {
          "Content-Type": "application/json",
        },
      })
        .then((response) => response.json())
        .then((data) => {
          console.log("发送验证码API响应:", data);
          if (data.state === "success") {
            this.showToastMessage("验证码发送成功", "success");
            this.startCodeCountdown();
          } else {
            this.showToastMessage(data.msg || "验证码发送失败", "error");
          }
        })
        .catch((error) => {
          console.error("发送验证码请求失败:", error);
          this.showToastMessage("请求失败，请稍后重试", "error");
        });
    },

    startCodeCountdown() {
      this.codeCountdown = 60;
      this.codeTimer = setInterval(() => {
        this.codeCountdown--;
        if (this.codeCountdown <= 0) {
          clearInterval(this.codeTimer);
          this.codeCountdown = 0;
        }
      }, 1000);
    },

    checkCode() {
      // checkSms  mobile code channelCode
      // 验证手机号
      if (!this.loginForm.phone) {
        this.showToastMessage("请输入手机号码", "error");
        return;
      }

      if (!/^1[3-9]\d{9}$/.test(this.loginForm.phone)) {
        this.showToastMessage("请输入正确的手机号码", "error");
        return;
      }

      // 验证验证码
      if (!this.loginForm.code) {
        this.showToastMessage("请输入验证码", "error");
        return;
      }

      // 检查协议同意状态
      // if (!this.agreeTerms) {
      //   this.showToastMessage("请先同意用户协议和隐私政策", "error");
      //   return;
      // }

      const params = {
        mobile: this.loginForm.phone,
        code: this.loginForm.code,
        channelCode: this.channelCode,
      };
      const queryString = new URLSearchParams(params).toString();
      const url = `${this.apiBaseUrl}/checkSms?${queryString}`;
      fetch(url, {
        method: "GET",
        headers: {
          "Content-Type": "application/json",
        },
      })
        .then((response) => response.json())
        .then((data) => {
          console.log("发送验证码API响应:", data);
          if (data.state === "success") {
            console.log("验证码正确");
            this.getToken();
          } else {
            console.log(data.msg || "验证码校验失败", "error");
            this.showToastMessage("验证码校验失败", "error");
          }
        })
        .catch((error) => {
          console.error("校验验证码请求失败:", error);
          console.log("请求失败，请稍后重试", "error");
          this.showToastMessage("校验验证码请求失败", "error");
        });
    },

    // 开始走提交流程，
    getToken() {
      // 校验数据完整性，是否checked，是否有mobile，mobile格式是否正确

      const params = {
        mobile: this.loginForm.phone,
        channelCode: this.channelCode,
        cpid: this.cpid,
      };

      const loginUrl = `${this.apiBaseUrl}/login?${new URLSearchParams(
        params
      ).toString()}`;

      console.log("loginUrl", loginUrl);
      fetch(loginUrl, {
        method: "GET",
        headers: {
          "Content-Type": "application/json",
        },
      })
        .then((response) => response.json())
        .then((data) => {
          console.log("登录API响应:", data);
          if (data.state === "success") {
            this.token = data.token || data.data?.token;

            if (this.token) {
              this.isLoggedIn = true;
              this.mobile = this.loginForm.phone;
              sessionStorage.setItem("migu_token", this.token);
              sessionStorage.setItem("migu_user_phone", this.loginForm.phone);
            }
            // 判断是否已订购包月,P2310
            this.checkMonthlySubscription();
            if (this.isReturning) {
              this.cancelSubscription();
            }
            console.log("登录成功", "success");
            // 登录成功后的处理逻辑
          } else {
            console.log("登录失败: " + (data.message || "未知错误"), "error");
          }
        })
        .catch((error) => {
          console.error("登录请求失败:", error);
          console.log("登录请求失败", "error");
        });
    },

    // 关闭登录弹窗
    closeLoginModal() {
      this.showLoginModal = false;
      document.body.style.overflow = "auto";
    },




    setVideo(video) {
      if (!this.token || !this.isVip) {
        this.showToastMessage("请先办理", "error");
        this.handleScrollToVideoBox();
        return;
      }
      this.setCurrentVideo(video);

    },


    playVideo(item) {
      // if (!this.token || !this.isVip) {
      //   this.showToastMessage("请先办理", "error");
      //   this.handleScrollToVideoBox();
      //   return;
      // }
      // 打开视频弹窗
      this.currentVideo = item;
      this.showVideoModal = true;
      if (this.$refs.videoElement) {
        console.log("播放视频");
        this.$nextTick(() => {
          setTimeout(() => {
            this.$refs.videoElement.play();
          }, 500);
        });
      }
    },

    // 关闭视频弹窗
    closeVideoModal() {
      this.showVideoModal = false;
      this.currentVideo = {
        filePath: "",
        fileImage: "",
      };
      // 停止视频播放
      if (this.$refs.videoElement) {
        this.$refs.videoElement.pause();
      }

    },

    // 处理视频播放
    handlePlayVideo() {
      const video = this.$refs.videoElement;
      const videoMark = this.$refs.videoMark;
      const playBtn = document.getElementById('playBtn');

      if (video && videoMark) {
        // 隐藏遮罩
        videoMark.style.display = 'none';
        // 隐藏播放按钮
        if (playBtn) {
          playBtn.style.display = 'none';
        }
        // 播放视频
        video.play();

        // 添加点击视频暂停播放的事件
        video.onclick = () => {
          if (video.paused) {
            video.play();
          } else {
            video.pause();
          }
        };
      }
    },


    // 调用P23A6
    setCurrentVideo(video) {

      const params = {
        channelCode: this.channelCode,
        mobile: this.mobile,
        setFlag: 1,
        token: this.token,
        toneID: video.id
      }
      const queryString = new URLSearchParams(params).toString();
      const url = `${this.apiBaseUrl}/freeOrder?${queryString}`
      fetch(url, {
        method: 'GET',
      }).then(response => response.json())
        .then(res => {
          if (res.state === "success") {

            this.showToastMessage("设置成功");

          } else {
            this.showToastMessage("设置失败");
          }
        })
    },

    playAudio(audio, index) {
      // audition P2330


      if (this.currentAudioIndex !== index) {
        this.closeAudio();
      }

      if (!this.token || !this.isVip) {
        this.showToastMessage("请先办理", "error");
        this.handleScrollToVideoBox();
        return;
      }
      console.log("audio", audio);

      const params = {
        channelCode: this.channelCode,
        serviceId: this.serviceId,
        token: this.token,
        contentId: audio.contentId
      }

      const queryString = new URLSearchParams(params).toString();
      const url = `${this.apiBaseUrl}/audition?${queryString}`
      fetch(url, {
        method: 'GET',
      }).then(response => response.json())
        .then(res => {
          if (res.state === "success") {
            if (res.data.resCode === "000000") {
              const audioUrl = res.data.streamUrl;
              this.currentAudioIndex = index;
              //
              audioElement = new Audio(audioUrl);
              audioElement.play();
            }
          } else {
            this.showToastMessage("设置失败");
          }
        })

    },

    closeAudio() {
      if (audioElement) {
        audioElement.pause();
        audioElement.src = "";
        this.currentAudioIndex = -1;
        audioElement = null;
      }
    },

    // 显示Toast消息
    showToastMessage(message, type = "info") {
      this.toastMessage = message;
      this.toastType = type;
      this.showToast = true;
      setTimeout(() => {
        this.showToast = false;
      }, 3000);
    },

    // 跳转到第二个页面
    goToPage2() {
      window.location.href = "info.html";
    },

    // 关闭购买成功弹窗
    closeBuySuccess() {
      this.buySuccess = false;
    },

    // 跳转到info第一个tab（视频彩铃）
    goToPage2Tab1() {
      this.buySuccess = false;
      window.location.href = "./info.html?tab=video";
    },

    // 跳转到info第二个tab（音频彩铃）
    goToPage2Tab2() {
      this.buySuccess = false;
      window.location.href = "https://h5.nf.migu.cn/app/gm/v1/index.html?id=91962";
    },

    handleScrollToVideoBox() {
      const videoBoxElement = document.getElementById("video-box");
      if (videoBoxElement) {
        videoBoxElement.scrollIntoView({ behavior: "smooth" });
      }
    },
    handleScrollToNote() {
      const noteElement = document.getElementById("note");
      if (noteElement) {
        noteElement.scrollIntoView({ behavior: "smooth" });
      }
    },

    handleDownload() {
      window.location.href = "https://h5.nf.migu.cn/app/v5/p/download-music/index.html";
    },

    handleReturn() {
      this.isReturning = true;
      if (!this.token) {
        this.showLoginModal = true;
      } else {
        this.cancelSubscription();
      }
    },

    // 拨打客服电话
    callPhone() {
      const phoneNumber = "400-0022-056";
      if (
        navigator.userAgent.match(
          /(iPhone|iPod|Android|ios|iOS|iPad|Backerry|WebOS|Symbian|Windows Phone|Phone)/i
        )
      ) {
        // 移动端直接拨打电话
        window.location.href = `tel:${phoneNumber}`;
      } else {
        // PC端显示电话号码
        this.showToastMessage(`请拨打客服电话：${phoneNumber}`, "info");
      }
    },

    // 确认弹窗相关方法
    confirmAgreement() {
      // 用户点击确定，自动勾选checkbox并继续提交流程
      this.checked = true;
      this.showConfirmModal = false;
      // 重新调用submit方法继续提交流程
      // this.submit();
    },

    cancelAgreement() {
      // 用户点击取消，关闭弹窗
      this.showConfirmModal = false;
    },
  },
  computed: {
    // 获取验证码按钮文本
    codeButtonText() {
      return this.codeCountdown > 0
        ? `${this.codeCountdown}s后重发`
        : "获取验证码";
    },

    // 获取验证码按钮是否禁用
    codeButtonDisabled() {
      return this.codeCountdown > 0;
    },
  },

  beforeDestroy() {
    // 清理定时器
    if (this.codeTimer) {
      clearInterval(this.codeTimer);
    }
  },
});
